<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 2018/9/19
 * Time: 10:44
 */

namespace common\models\db;


/**
 * Class Tag
 * @package common\models\db
 *
 * @property DocuTag[] $docuTags
 * @property Docu[] $docus
 */
class Tag extends \common\models\db\tables\Tag
{
    public static function findAllByName($query)
    {
        $tags = static::find()->where(['like', 'name', $query])->limit(10)->all();
        return $tags;
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuTags()
    {
        return $this->hasMany(DocuTag::className(), ['tag_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocus()
    {
        return $this->hasMany(Docu::className(), ['id' => 'docu_id'])->viaTable('{{%docu_tag}}', ['tag_id' => 'id']);
    }
}